<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
    <head>
        <title>美业红</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1">
        <link href="http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
        <link href="/public/css/main.css" rel="stylesheet">
        <script type='text/javascript' src='/public/js/jquery-3.1.1.min.js'></script>
        <script type="text/javascript" src='/public/js/jquery.validate.js'></script>
        <script type="text/javascript" src='/public/js/main/main.js'></script>
        <script>
            var _hmt = _hmt || [];
            (function () {
                var hm = document.createElement("script");
                hm.src = "//hm.baidu.com/hm.js?8d43b5b5d798921b66d689f7a792e6e2";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);
            })();
        </script>
        <script type="text/javascript">
            document.domain = '<?php echo _DOMAIN_ALL_;?>';
        </script>
        <link rel="shortcut icon" type="image/ico" href="/favicon.ico">
    </head>
    <body style="background-color: #f4f4f4;">
        <div class="navigation">
            <div class='navlogo'>
            <a href='/'><img class='_navlogo' src="/public/images/logo.png"></a>
            </div>
            <div class='navson'>
                <ul class='fr'>
                <li><a href='/' class='anchor'><b>主页</b></a></li>
                <li><a href="/home/store" class='anchor'><b>店铺</b></a></li>
                <li><a href="/home/barber" class='anchor'><b>成员</b></a></li>
                <li><a href="/home/action" class='anchor'><b>活动</b></a></li>
                <li><a href="/home/order" class='anchor'><b>订单</b></a></li>
                <li><a href="/home/coupon" class='anchor'><b>优惠券</b></a></li>
                <li><a href="/home/goods" class='anchor'><b>商品</b></a></li>
                </ul>
           </div>
            <?php if($_SESSION['id']>0){?>
            <div style="float:right;padding-right:10%">你好:<span id='login_name'></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class='anchor' href='/home/passport/repassword'>修改密码</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class='anchor' href='/home/passport/logout'>退出</a></div>
            <?php }?>
        </div>
        <div style='margin-top:80px;width:100%'>
            <img class='_navlogo' src="/public/images/contentlogo.png" style='width:100%;height:100px'>
        </div>
        <div class='container'>
            <div class='_main'>
            <div class='_line'></div> 
<div class="_contro">
    <select id="store_id" >
        <option value='0'>全部店铺</option>
        <?php foreach($store as $v){?>
        <option value='<?php echo $v['id'];?>' <?php if($store_id==$v['id']){echo "selected='selected'";}?>><?php echo $v['name'];?></option>
        <?php }?>
    </select>&nbsp;&nbsp;&nbsp;&nbsp;
    <select id="type" >
        <option value='0'>产品类型</option>
        <option value='1'<?php if($type == 1){echo 'selected="selected"';}?> >套餐</option>
        <option value='2'<?php if($type == 2){echo 'selected="selected"';}?> >单品</option>
        
        
    </select>&nbsp;&nbsp;&nbsp;&nbsp;
    <select id="status" >
        <option value='0' >产品状态</option>
        <option value='1' <?php if($status == 1){echo 'selected="selected"';}?> >已上架</option>
        <option value='2' <?php if($status == 2){echo 'selected="selected"';}?> >未上架</option>
    </select>&nbsp;&nbsp;&nbsp;&nbsp;
    <a href="/home/goods/create" class="_a"><font class="_font"><b>+</b>添加商品</font></a>
</div>
<div class='_cut'></div>
<div id='content'>
   <?php foreach ($items as $key => $value) { ?>
    <?php if($key%4 == 0){ ?>
    <div class='row'>
        <?php } ?>
        <div class='col-sm-4 col-md-3 full'>
            <div class='thumbnail' style="margin-bottom:10px">
                <div style="height:19rem; overflow: hidden">
                    <a href="/home/goods/detail?id=<?php echo $value['id'] ?>&store_id=<?php echo $value['store_id'];?>" >
                        <img class='_img' src="<?php echo "http://".IMAGE_DOMAIN.$value['images'][0]['image']; ?>" style='width:100%;height:100%' />
                    </a>
                </div>
            
            <div class='caption' style='overflow: hidden'>
                <div style='font-size:1.5rem'>
                    <div >
                        <img class='_img' src="/public/images/<?php echo $value['img'] ?> " style='width:30%;'/>
                        <span style="margin-left: 6px;"><?php echo $value['name'];?></span>
                    </div>
                    <div>
                        <span ><?php if($value['status']==1){ echo '已上架';}else{ echo '未上架'; }?></span>
                        <span style="float:right;color:red;">￥<?php echo ($value['price']/100);?>元</span>
                    </div>
                    <div style="float:right;">
                        <a href="/home/goods/detail?id=<?php echo $value['id'] ?>&store_id=<?php echo $value['store_id'];?>" >详情 </a>&nbsp;&nbsp;
                        <?php  if($value['status']==1){ ?>
                        <a href="/home/evaluate?store_id=<?php echo $value['store_id'];?>&id=<?php echo $value['id']?>"  id='evaluate'  >查看评价</a>&nbsp;
                        <a href="javascript:;"  id='soldOut' onclick="soldOut(<?php echo $value['id']; ?>,<?php echo $value['store_id'];?>)" >下架</a>
                        <?php }else{ ?>
                        <a href="/home/goods/create?id=<?php echo $value['id'] ?>&store_id=<?php echo $value['store_id'];?>" >修改 </a>&nbsp;&nbsp;
                        <a href="javascript:;"  id='del' onclick="del(<?php echo $value['id']; ?>,<?php echo $value['store_id'];?>)"  >删除</a>
                        <?php } ?>
                    </div>
                </div>
            </div> 
            </div> 
        </div>
        <?php if(($key+1)%4==0 || $items[$key+1]['id']<1){ ?>
    </div>
    <?php } ?>
    <?php } ?> 

</div>
<div class='_line'></div>
<div class="clear"></div>
<script type="text/javascript">
    $(document).ready(function(){
         $("#store_id").change(function () {
            var store_id = $("#store_id").val();
            var type = $("#type").val();
            var status = $('#status').val();
            setTimeout(window.location.href = '/home/goods/search?store_id=' + store_id + '&type=' + type+'&status='+status+'&start=0');
        });
        $("#type").change(function () {
            var store_id = $("#store_id").val();
            var type = $("#type").val();
            var status = $('#status').val();
            setTimeout(window.location.href = '/home/goods/search?store_id=' + store_id + '&type=' + type+'&status='+status+'&start=0');
        });
        $("#status").change(function () {
            var store_id = $("#store_id").val();
            var type = $("#type").val();
            var status = $('#status').val();
            setTimeout(window.location.href = '/home/goods/search?store_id=' + store_id + '&type=' + type+'&status='+status+'&start=0');
        });
    });

    function del(id,store_id){
            if(confirm("确认删除该商品?")){
                if(confirm("删除商品后可能会影响有关该商品的活动,确认继续?")){
                    $.ajax({url:"/home/goods/delete?id="+id+"&store_id="+store_id,async:true, 
                        success: function(msg){
                           if(msg==1){
                                alert('删除成功!');
                                window.location.reload();
                           }else{
                                alert('删除失败!');
                           }  
                        }
                    });
                }
            }
    }
    function soldOut(id,store_id){
            if(confirm("下架商品后可能会影响有关该商品的活动,确认继续?")){
                    $.ajax({url:"/home/goods/soldOut?id="+id+"&store_id="+store_id,async:true, 
                        success: function(msg){
                           if(msg=='1'){
                                alert('下架成功!');
                                window.location.reload();
                           }else{
                                alert('下架失败!');
                           } 
                        }
                    });
            }
    }


    var number = 12;
    function loaddata()
    {
        var status = $("#status").val();
        var type = $("#type").val();
        var store_id = $("#store_id").val();
        if (number == -1) {
            return;
        }
        totalheight = parseFloat($(window).height()) + parseFloat($(window).scrollTop());

        if ($(document).height() <= totalheight)
        {
            $.ajax({url: "/home/goods/search?store_id="+store_id+"&status=" + status + "&type=" + type + "&start=" + number, async: true, 
                success: function (msg) {
                    if (msg == '') {
                        number = -1;
                        return;
                    }

                    var html = "";
                    msg = eval('(' + msg + ')');
                        $.each(msg, function (i,v){

                            var image= '';
                            $.each(v.images, function (x,y){
                                http = "<?php echo 'http://'.IMAGE_DOMAIN; ?>";
                                image = http+y.image;  
                            });

                            if (i % 4 == 0) {
                                html += "<div class='row'>";
                            }
                            
                            html += "<div class='col-sm-4 col-md-3 full'>";
                            html += "<div class='thumbnail' style='margin-bottom:10px'>";
                            html += "<div style='height:19rem; overflow: hidden'>";
                            html += "<a href='/home/goods/detail?id=";
                            html += v.id==null?'':v.id;
                            html += "'><img class='_img' src='";
                            html += image==null?'':image;
                            html += "' width='100%' height='100%' /></a></div>";
                            html += "<div class='caption' style='overflow: hidden'>";
                            html += "<div style='font-size:1.5rem'><div >";
                            html += "<img class='_img' src='/public/images/";
                            html += v.img==null?'':v.img;
                            html += "' style='width:30%;'/>";
                            html += "<span style='margin-left: 6px;'>";
                            html += v.name==null?'':v.name;
                            html += "</span></div><div><span >";
                            status = v.status;
                            if(status==1){
                                html += '已上架';
                            }else{
                                html += '未上架';
                            }
                            html += "</span><span style='float:right;color:red;'>￥";
                            html += v.price==null?'':(v.price/100);
                            //html += "</span><div><span >销售量：";
                            //html += v.num==null?'0':v.num;
                            html += "元</span></div><div style='float:right;'>";
                            html += "<a href='/home/goods/detail?id=";
                            html += v.id==null?'':v.id;
                            html += "&store_id=";
                            html += v.store_id==null?'':v.store_id;
                            html +="'>详情 </a>";
                            status = v.status;
                            if(status==1){
                                html += "<a href='/home/evaluate?store_id=";
                                html += v.store_id==null?'':v.store_id;
                                html += "&id=";
                                html +=  v.id==null?'':v.id; 
                                html += " ' id='evaluate' >查看评价</a>&nbsp;";
                                html += "<a href='javascript:;'  id='soldOut' onclick='soldOut(";
                                html += v.id==null?'':v.id; 
                                html +=",";
                                html += v.store_id==null?'':v.store_id;
                                html += ") '>下架</a>";
                            }else{
                                html += "<a href='/home/goods/create?id=";
                                html += v.id==null?'':v.id;
                                html += "&store_id=";
                                html += v.store_id==null?'':v.store_id;
                                html += "'>修改 </a>";
                                html += "<a href='javascript:;'  id='del' onclick='del(";
                                html +=  v.id==null?'':v.id;
                                html += ",";
                                html += v.store_id==null?'':v.store_id;
                                html += ")' >删除</a>";
                            }
                            html += "</div>";
                            html +=" </div></div></div></div>";
                            if ((i + 1) % 4 == 0) {
                                html += "</div>";
                            }
                            i++;
                            number += 1;
                        });
                    $('#content').append(html);
                }});
        }
    }

    $(window).scroll(function () {
        loaddata();
    });

</script>

</div>
</div>
<div class='_line'></div>
<div class="newfooter">
    ©2015-2017 All Rights Reserved ( 京ICP备15010043号 ) 
</div>
<div id='mask_layer' style="text-align: center;width:100%;height:100%;overflow:hidden;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#8E8E8E',endColorstr='##8E8E8E');
     background-color:rgba(255, 255, 255, 0.4);position:fixed; _position:absolute; top:0;left:0; z-index:5000;display:none ">
    <div style="padding-top: 20%"><h1><b>loading<span id="_loading"></span></b></h1></div>
</div>
</body>
<script type="text/javascript" src='/public/js/top.js'></script>
</html>